﻿
@{
    ViewBag.Title = "修改店铺";
}
@section CSS{
    <link href="~/Content/css/layerui/layui.css" rel="stylesheet" />
}
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <section class="content-header">
        <h1>
            修改
            <small>店铺</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="#">商家管理</a></li>
            <li><a href="/shop/company">店铺列表</a></li>
            <li class="active">修改店铺</li>
        </ol>
    </section>
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box">
                    <div class="box-body">
                        <div class="ibox float-e-margins">
                            <div class="ibox float-e-margins">
                                <div class="ibox-content">
                                    <form class="form-horizontal" id="from-add" novalidate="novalidate" method="post" action="/shop/AddorEditShopInfo">
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">店铺名称 <span style="color:red;">*</span>：</label>
                                            <div class="col-sm-9">
                                                <input type="text" name="name" required="" maxlength="11" aria-required="true" id="name" class="form-control" placeholder="给店铺取个响亮的名字吧" />
                                                <span class="help-block m-b-none">名称3-15个字,店铺名称不可重复,提交后不可修改,请认真填写</span>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">店铺类型：</label>
                                            <div class="col-sm-9 ">
                                                <select class="form-control " style="width: 200px; " name="sGrade" id="sGrade" required="" aria-required="true">
                                                    <option value="0">普通店</option>
                                                    <option value="1">专营店</option>
                                                    <option value="2">专卖店</option>
                                                    <option value="3">旗舰店</option>
                                                </select>
                                                <span class="help-block m-b-none">说明:"专营店、专卖店、旗舰店"必须上传【品牌授权证明】或【商标注册证明】</span>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">店铺Logo：</label>
                                            <div class="col-sm-9">
                                                <button type="button" class="layui-btn" id="test4">请上传店铺logo</button>
                                                <div class="layui-upload-list">
                                                    <img class="layui-upload-img" id="logo_img" onclick="javascript:imgzoom(this.id)" style="width: 150px; height: 150px; cursor: pointer">
                                                    <p id="demoText4"></p>
                                                </div>
                                                <span class="help-block m-b-none">图片大小不超过1M</span>

                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">账期(天)：</label>
                                            <div class="col-sm-9">
                                                <input type="number" name="account_period" id="account_period" value="1" class="form-control" placeholder="请输入账期" />
                                                <span class="help-block m-b-none"></span>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">店铺管理人姓名：</label>
                                            <div class="col-sm-9">
                                                <input type="text" name="mangername" id="mangername" value="" class="form-control" placeholder="请输入店铺管理人员的姓名,与身份证一致" />
                                                <span class="help-block m-b-none"></span>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">管理人手机号码 <span style="color:red;">*</span>：</label>
                                            <div class="col-sm-9">
                                                <input type="text" name="mangermobile" id="mangermobile" value="" class="form-control" placeholder="请输入店铺管理人的手机号码" required="" aria-required="true" />
                                                @*<span class="help-block m-b-none">注：此手机号将作为店铺登陆账号和接收登陆密码的手机号</span>*@
                                                <span class="help-block m-b-none">注：此手机号将作为店铺登陆账号,初始密码：qj+店铺编号</span>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">管理人邮箱：</label>
                                            <div class="col-sm-9">
                                                <input type="text" name="email" id="email" value="" class="form-control" placeholder="请输入店铺管理人邮箱" />
                                                <span class="help-block m-b-none"></span>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">客服座机：</label>
                                            <div class="col-sm-9">
                                                <input type="text" name="telephone" id="telephone" value="" class="form-control" placeholder="请输入客服座机" />
                                                <span class="help-block m-b-none"></span>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">客服手机号：</label>
                                            <div class="col-sm-9">
                                                <input type="text" name="mobile" id="mobile" value="" class="form-control" placeholder="请输入客服手机号" />
                                                <span class="help-block m-b-none">注：多个手机号，请用英文“,”隔开</span>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">客服QQ号：</label>
                                            <div class="col-sm-9">
                                                <input type="text" name="qq" id="qq" value="" class="form-control" placeholder="请输入客服QQ号" />
                                                <span class="help-block m-b-none"></span>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">客服微信号：</label>
                                            <div class="col-sm-9">
                                                <input type="text" name="wechat" id="wechat" value="" class="form-control" placeholder="请输入客服微信号" />
                                                <span class="help-block m-b-none"></span>
                                            </div>
                                        </div>


                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">管理人身份证信息上传：</label>
                                            <div class="col-sm-3">
                                                <div class="layui-upload">
                                                    <button type="button" class="layui-btn" id="test2">管理人身份证正面</button>
                                                    <div class="layui-upload-list">
                                                        <img class="layui-upload-img" id="face_card_img" onclick="javascript:imgzoom(this.id)" style="width: 150px; height: 150px; cursor: pointer">
                                                        <p id="demoText2"></p>
                                                    </div>
                                                </div>
                                                <span class="help-block m-b-none">图片大小不超过1M</span>

                                            </div>
                                            <div class="col-sm-3">
                                                <div class="layui-upload">
                                                    <button type="button" class="layui-btn" id="test3">管理人身份证反面</button>
                                                    <div class="layui-upload-list">
                                                        <img class="layui-upload-img" id="opposite_card_img" onclick="javascript:imgzoom(this.id)" style="width: 150px; height: 150px; cursor: pointer">
                                                        <p id="demoText3"></p>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-sm-3">
                                                <div class="layui-upload">
                                                    <button type="button" class="layui-btn" id="test1">管理人手持身份证半身照</button>
                                                    <div class="layui-upload-list">
                                                        <img class="layui-upload-img" id="half_card_img" onclick="javascript:imgzoom(this.id)" style="width: 150px; height: 150px; cursor: pointer">
                                                        <p id="demoText1"></p>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">管理人身份证有效期：</label>
                                            <div class="col-sm-3">
                                                <input type="text" name="card_date" id="card_date" placeholder="法人身份证有效期" class="form-control pull-right">
                                                <span class="help-block m-b-none"></span>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">开店起止日期：</label>
                                            <div class="col-sm-3">
                                                <input type="text" name="start_date" id="start_date" placeholder="开始日期" class="form-control pull-right ">
                                                <span class="help-block m-b-none"></span>
                                            </div>
                                            <label style="float:left;"> - </label>
                                            <div class="col-sm-3">
                                                <input type="text" name="end_date" id="end_date" placeholder="到期日期" class="form-control pull-right">
                                                <span class="help-block m-b-none"></span>
                                            </div>
                                        </div>
                                        <div class="hr-line-dashed"></div>

                                        <input type="hidden" id="id" value="0" name="id">
                                        <input type="hidden" id="supplier_id" value="0" name="supplier_id">
                                        <input type="hidden" id="half_card" value="" name="half_card">
                                        <input type="hidden" id="opposite_card" value="" name="opposite_card">
                                        <input type="hidden" id="face_card" value="" name="face_card">
                                        <input type="hidden" id="logo" value="" name="logo">
                                        <input type="hidden" id="grade" value="0" name="grade">
                                        <div class="form-group">
                                            <div class="col-sm-4 col-sm-offset-3">
                                                <button class="btn btn-primary" type="submit">保存信息</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

</div>

@section JS{
    <script src="~/Content/js/jquery.form.js"></script>
    <script src="~/Content/plugins/validate/jquery.validate.min.js"></script>
    <script src="~/Content/plugins/validate/messages_zh.min.js"></script>

    <script type="text/javascript">
         var _id="@ViewBag.id";
        $('#start_date').datepicker({
            autoclose: true
        });
        $('#end_date').datepicker({
            autoclose: true
        });
        $('#card_date').datepicker({
            autoclose: true
        });
        $(function () {
            if (_id != undefined && _id!="0")
            {
                getinfo(_id);
            }
            else{
                layer.alert('信息获取失败，请重试！', { icon: 5 });
             }
        });


        function getinfo(_id) {
            ajax("/shop/storeInfo/" + _id, {}, function (data) {
                if (data!= null) {
                    $("#id").val(data.id);
                    $("#name").val(data.name);
                    $("#telephone").val(data.telephone);
                    $("#mobile").val(data.mobile);
                    $("#wechat").val(data.wechat);
                    $("#qq").val(data.qq);
                    $("#email").val(data.email);
                    $("#grade").val(data.grade);
                    $("#sGrade").val(data.grade);
                    $("#account_period").val(data.account_period);
                    if (data.logo!="") {
                        $("#logo_img").attr('src', domain + data.logo);
                    }
                    if (data.opposite_card != "") {
                        $("#opposite_card_img").attr('src', domain + data.opposite_card);
                    }
                    if (data.face_card != "") {
                        $("#face_card_img").attr('src', domain + data.face_card);
                    }
                    if (data.half_card != "") {
                        $("#half_card_img").attr('src', domain + data.half_card);
                    }
                    $("#logo").val(data.logo);
                    $("#half_card").val(data.half_card);
                    $("#face_card").val(data.face_card);
                    $("#opposite_card").val(data.opposite_card);
                    $("#card_date").val((data.card_date==null?"":moment(data.card_date).format("YYYY-MM-DD")));
                    $("#start_date").val((data.start_date==null?"":moment(data.start_date).format("YYYY-MM-DD")));
                    $("#end_date").val((data.end_date==null?"":moment(data.end_date).format("YYYY-MM-DD")));
                    $("#mangername").val(data.mangername);
                    $("#mangermobile").val(data.mangermobile);
                    //店铺唯一，禁止修改
                    $("#name").attr("readonly", "readonly");
                    $("#mangermobile").attr("readonly", "readonly");
                }
                else {
                    layer.alert('信息获取失败，请重试！', { icon: 5 });
                }
            }, true, "", "get");
        }
        $("#sGrade").change(function () {
            var _mId = $(this).val();
            if (_mId != "") {
                $("#grade").val(_mId);
            }
        });
        $("#from-add").validate({
            ajaxPost: true,
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    dataType: "json",
                    success: function (result) {
                        if (result.status == "y") {
                            layer.msg("操作成功", { icon: 6, time: 1200 }, function () {
                                window.location.href = "/shop/Store/";
                            });
                        }
                        else {
                            layer.msg(result.info, { icon: 5, time: 2000 });
                        }
                    }
                });
            }
        });

        //图片点击跳转
        function imgzoom(obj) {
            var img = document.getElementById(obj).src
            if (!!img) {
                onclick = window.open(img)
            }
        }
        //后期可重构一个方法
        layui.use('upload', function () {
            var $ = layui.jquery
                , upload = layui.upload;
            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                , url: domain + "/tools/UploadPCImage?type=shop"
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#half_card_img').attr('src', result); //图片链接（base64）

                    });
                },

                done: function (res) {
                    $('#half_card_img').attr('src', domain + res.info);
                    $('#half_card').val(sqlImgdomain + res.info);
                }
                , error: function () {
                    //，并实现重传
                    var demoText = $('#demoText1');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
            var uploadInst = upload.render({
                elem: '#test2'
                , url: domain + "/tools/UploadPCImage?type=shop"
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#face_card_img').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    $('#face_card_img').attr('src', domain + res.info);
                    $('#face_card').val(sqlImgdomain+res.info);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText2');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
            var uploadInst = upload.render({
                elem: '#test3'
                , url: domain + "/tools/UploadPCImage?type=shop"
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#opposite_card_img').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    $('#opposite_card_img').attr('src', domain + res.info);
                    $('#opposite_card').val(sqlImgdomain+res.info);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText3');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });

         var uploadInst = upload.render({
                elem: '#test4'
                , url: domain + "/tools/UploadPCImage?type=shop"
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#logo_img').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    $('#logo_img').attr('src', domain + res.info);
                    $('#logo').val(sqlImgdomain+res.info);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText4');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
        });

    </script>
}


